package report 
{
	import morn.core.handlers.Handler;
	import org.airmvc.Controller;
	import org.airmvc.ModulesManager;
	import utils.T;
	import vo.CastleVO;
	import vo.GeneralVO;
	
	/**
	 * ...
	 * @author WLDragon 2014-02-28
	 */
	public class ReportC extends Controller 
	{
		
		public function ReportC() 
		{
			super();
		}
		
		override protected function addListeners():void 
		{
			interest(Nws.REPORT_PLAY_INCIDENT, handlePlayIncident);
			interest(Nws.REPORT_PLOT_CASE, playPlotCase);
		}
		
		private function playPlotCase(id:int,g:GeneralVO,callBack:Handler):void 
		{
			send(PLAY_PLOT_CASE,id,g,callBack);
		}
		
		private function handlePlayIncident(id:int,callBack:Function = null):void 
		{
			if (id == 0)
			{
				send(PLAY_INCIDENT,null);
			}
			else
			{
				var x:XML = T.db.getXml(Cnt.XML_INCIDENT).incident.(@id == id)[0];
				if (x != null)
				{
					if (curCastle != Gbl.activeCastle)
					{
						curCastle = Gbl.activeCastle;
						//计算应该在左侧还是右侧显示>256左
						var xml:XML = T.db.getXml(Cnt.XML_CASTLE).castle.(@id == curCastle.id)[0];
						var tx:int;
						//var ty:int = 49;
						if (int(xml.@x) > 256)
							tx = 32;
						else
							tx = 256;
						
						curX = tx;
					}
					
					send(PLAY_INCIDENT, x.@url,callBack, curX, 49);
				}
			}
		}
		
		override protected function startup(... args):void 
		{
			//初始化视图
			if (view == null)
			{
				view = new ReportV();
				registerView(view);
			}
		}
		
		private var curCastle:CastleVO;
		private var curX:int;
		
		/**播放事件动画*/
		static public const PLAY_INCIDENT:String = "play_incident";
		/**播放计谋事件动画*/
		static public const PLAY_PLOT_CASE:String = "play_plot_case";
	}
	
}